[Android] Pass variable/intent to an activity when launched from a Widget

Posted by Pelly on Stack Overflow See other posts from Stack Overflow or by Pelly
Published on 2010-12-21T23:30:06Z Indexed on 2010/12/22 4:54 UTC
Read the original article Hit count: 193

Filed under:
|
|

Hi,

Currently within an activity in my application I can call another activity and pass a variable to it in the following manner:

Intent myIntent = new Intent(parentView.getContext(), ShowStations.class);
myIntent.putExtra("stationName", stations[position].StationName);
startActivity(myIntent);

This works fine, but now I want to be able to do the same from my Widget. Currently this code works fine for launching a specific activity from my widget:

Intent WidgetIntent = new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_LAUNCHER).setComponent(new ComponentName("grell.com", "grell.com.FavStations"));
    PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, WidgetIntent, 0);
    updateViews.setOnClickPendingIntent(R.id.widget_main, pendingIntent);

So now I am wondering how can I launch the same activity as shown in the first example but also pass through the 'stationName' variable.

Any help would be greatly appreciated.

Cheers

© Stack Overflow or respective owner

Related posts about android

Related posts about activity